﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class GroupNewsItems : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "GroupNewsItems";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId, "GroupNewsItemHeader", "Chi tiết nhóm tin");
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetHtml(string GroupNewsId)
        {
            try
            {
                Environments.CheckWebPartAllow(new GroupNews().WebPartId, true);
                Environments.CheckSessionTimeOut(true);

                string AddUrl = "javascript:ClientShowAddGroupNewsItemRootForm('" + GroupNewsId + "');";
                string RetHtml = "<div style=\"text-align:right;\"><input type=button onclick=\"" + AddUrl + "\" value=\"" + ResourceBLL.GetText(WebPartId, "AddRoot", "Thêm mới") + "\">&nbsp;<input onclick=\"javascript:ClientUpdateLevelIndex('" + GroupNewsId + "');\" type=button value=\"" + ResourceBLL.GetText(WebPartId, "UpdateLevelIndex", "Cập nhật chỉ mục") + "\"><input onclick=\"javascript:ClientReadingGroupNewsItem('" + GroupNewsId + "');\" type=button value=\"" + ResourceBLL.GetText(WebPartId, "ClientReading", "Đọc lại") + "\">&nbsp;<input type=button onclick=\"javascript:window.close();\" value=\"" + ResourceBLL.GetText(WebPartId, "Back", "Quay lại") + "\"></div>";

                DataTable dtGroupNewsItem = new GroupNewsBLL().ReadingGroupNewsItems(GroupNewsId, null);
                if (dtGroupNewsItem.Rows.Count == 0)
                {
                    RetHtml += "<div class=\"cssNoData\">" + ResourceBLL.GetText(WebPartId, "NoData", "Chưa có dữ liệu nào trong chuyên mục này!") + "</div>";
                }
                else
                {
                    RetHtml += 
                        "<div id=divProcessing></div>\r\n"+
                        "<table>";
                    for (int iIndex = 0; iIndex < dtGroupNewsItem.Rows.Count; iIndex++)
                    {
                        string GroupNewsItemName = (string)dtGroupNewsItem.Rows[iIndex][Environments.ActiveLanguage + "GroupNewsItemName"];
                        string GroupNewsItemId = (string)dtGroupNewsItem.Rows[iIndex]["GroupNewsItemId"];
                        string belongSite = (string)dtGroupNewsItem.Rows[iIndex]["belongSite"];
                        string GroupNewsItemAlias = "";
                        try
                        {
                            GroupNewsItemAlias = (string)dtGroupNewsItem.Rows[iIndex]["GroupNewsItemAlias"];
                        }
                        catch { }
                        string LinkText = Environments.GetNewsCategoryUrl(belongSite, GroupNewsItemId, GroupNewsItemName, "_runtime");
                        LinkText = LinkText.Substring(LinkText.LastIndexOf("/") + 1);

                        string LinkHtml = Environments.GetHtmlByMenu(belongSite, GroupNewsItemId, GroupNewsItemName);
                        LinkHtml = LinkHtml.Substring(LinkHtml.LastIndexOf("/") + 1);

                        string AddSubUrl = "javascript:ClientShowAddGroupNewsItemSubForm('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string DeleteUrl = "javascript:DeleteGroupNewsItem('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string UpdateUrl = "javascript:ClientShowUpdateGroupNewsItemSubForm('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string PermissionUrl = "javascript:ClientPermissionGroupNewsItem('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string HtmlContentUrl = "javascript:ClientHtmlItem('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string ImageUrl = "javascript:ClientImageItem('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string SyncText = "javascript:ClientSync('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        string SyncWithNewsText = "javascript:ClientSyncWithNews('" + GroupNewsId + "','" + GroupNewsItemId + "');";
                        int AllowRss = 0;
                        if (dtGroupNewsItem.Rows[iIndex]["AllowRss"] != DBNull.Value)
                        {
                            AllowRss = (int)dtGroupNewsItem.Rows[iIndex]["AllowRss"];
                        }
                        int Ident = 5;
                        RetHtml +=
                                   "<tr>" +
                                   "    <td valign=top class=cssMainGroupAlias>" + GroupNewsItemAlias + "</td>" +
                                   "    <td valign=top class=cssMainGroupNewsName><div>" + "+ &nbsp<b><i>" + GroupNewsItemName + "</i></b>&nbsp;<input class=cssButtonShowLink type=button onclick=javascript:ClientShowLink('" + belongSite + "','" + GroupNewsItemId + "'); value=\"=>\"></div><div id=\"divShowUrl_" + GroupNewsItemId + "\"></div></td>" +
                                   "    <td valign=top><a href=\"" + UpdateUrl + "\">" + ResourceBLL.GetText(WebPartId, "Modify", "sửa") + "</a></td>" +
                                   "    <td valign=top><a href=\"" + DeleteUrl + "\">" + ResourceBLL.GetText(WebPartId, "Delete", "xóa") + "</a></td>" +
                                   "    <td valign=top><a href=\"" + AddSubUrl + "\">" + ResourceBLL.GetText(WebPartId, "AddSub", "(Thêm)") + "</a></td>" +
                                   "    <td valign=top><a href=\"" + PermissionUrl + "\">" + ResourceBLL.GetText(WebPartId, "Permission", "(Quyền)") + "</td>" +
                                   //"    <td valign=top><a href=\"" + HtmlContentUrl + "\">" + ResourceBLL.GetText(WebPartId, "Html", "(Html)") + "</a></td>" +
                                   //"    <td valign=top><a href=\"" + ImageUrl + "\">" + ResourceBLL.GetText(WebPartId, "Image", "(Image)") + "</a></td>" +
                                   //"    <td valign=top><a href=\"" + SyncText + "\">" + ResourceBLL.GetText(WebPartId, "Sync", "(Sync)") + "</a></td>" +
                                   //"    <td valign=top><a href=\"" + SyncWithNewsText + "\">" + ResourceBLL.GetText(WebPartId, "SyncWithNewsText", "(Sync/News)") + "</a></td>" +
                                   //"    <td valign=top>"+(AllowRss==1?"RSS":"---")+"</td>" +
                                   "</tr>" + ReadingSub(belongSite, GroupNewsId, GroupNewsItemId, ref Ident);
                    }
                    RetHtml += "</table>";
                }
                return RetHtml;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        public string ReadingSub(string belongSite, string GroupNewsId, string GroupNewsItemId, ref int Ident)
        {
            string RetHtml = "";
            DataTable dtGroupNewsSubItems = new GroupNewsBLL().ReadingGroupNewsItems(GroupNewsId, GroupNewsItemId);
            for (int zIndex = 0; zIndex < dtGroupNewsSubItems.Rows.Count; zIndex++)
            {
                belongSite = (string)dtGroupNewsSubItems.Rows[zIndex]["belongSite"];
                string SubGroupNewsItemName =  (string)dtGroupNewsSubItems.Rows[zIndex][Environments.ActiveLanguage + "GroupNewsItemName"];
                for (int iIden = 0; iIden < Ident; iIden++)
                {
                    SubGroupNewsItemName = "-" + SubGroupNewsItemName;
                }
                string SubGroupNewsItemId = (string)dtGroupNewsSubItems.Rows[zIndex]["GroupNewsItemId"];
                string PermissionItemUrl = "javascript:ClientPermissionGroupNewsItem('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";
                string AddSubUrl = "javascript:ClientShowAddGroupNewsItemSubForm('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";

                string LinkText = Environments.GetNewsCategoryUrl(belongSite, SubGroupNewsItemId, SubGroupNewsItemName, "_runtime");
                LinkText = LinkText.Substring(LinkText.LastIndexOf("/") + 1);
                string LinkHtml = Environments.GetHtmlByMenu(belongSite, SubGroupNewsItemId, SubGroupNewsItemName);
                LinkHtml = LinkHtml.Substring(LinkHtml.LastIndexOf("/") + 1);
                int AllowRss = 0;
                if (dtGroupNewsSubItems.Rows[zIndex]["AllowRss"] != DBNull.Value)
                {
                    AllowRss = (int)dtGroupNewsSubItems.Rows[zIndex]["AllowRss"];
                }
                string GroupNewsItemAlias = "";
                try
                {
                    GroupNewsItemAlias = (string)dtGroupNewsSubItems.Rows[zIndex]["GroupNewsItemAlias"];
                }
                catch { }

                string DeleteUrl = "javascript:DeleteGroupNewsItem('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";
                string UpdateUrl = "javascript:ClientShowUpdateGroupNewsItemSubForm('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";
                string HtmlContentUrl = "javascript:ClientHtmlItem('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";
                string ImageUrl = "javascript:ClientImageItem('" + GroupNewsId + "','" + SubGroupNewsItemId + "');";
                string SyncText = "javascript:ClientSync('" + GroupNewsId + "','" + GroupNewsItemId + "');";

                Ident = Ident + 5;
                RetHtml += " <tr>" +
                           "    <td valign=top class=cssMainGroupAlias>" + GroupNewsItemAlias + "</td>" +
                           "        <td valign=top class=cssSubGroupNewsName><div>" + SubGroupNewsItemName + "&nbsp;<input class=cssButtonShowLink type=button onclick=javascript:ClientShowLink('" +belongSite+"','"+ SubGroupNewsItemId + "'); value=\"=>\"></div><div id=\"divShowUrl_" + SubGroupNewsItemId + "\"></div></td>" +
                           "        <td valign=top><a href=\"" + UpdateUrl + "\">" + ResourceBLL.GetText(WebPartId, "Modify", "sửa") + "</a></td>" +
                           "        <td valign=top><a href=\"" + DeleteUrl + "\">" + ResourceBLL.GetText(WebPartId, "Delete", "xóa") + "</a></td>" +
                           "        <td valign=top><a href=\"" + AddSubUrl + "\">" + ResourceBLL.GetText(WebPartId, "AddSub", "(Thêm)") + "</a></td>" +
                           "        <td valign=top><a href=\"" + PermissionItemUrl + "\">" + ResourceBLL.GetText(WebPartId, "Permission", "(Quyền)") + "</a></td>" +
                           //"        <td valign=top><a href=\"" + HtmlContentUrl + "\">" + ResourceBLL.GetText(WebPartId, "Html", "(Html)") + "</a></td>" +
                           //"        <td valign=top><a href=\"" + ImageUrl + "\">" + ResourceBLL.GetText(WebPartId, "Image", "(Image)") + "</a></td>" +
                           //"        <td valign=top><a href=\"" + SyncText + "\">" + ResourceBLL.GetText(WebPartId, "Sync", "(Sync)") + "</a></td>" +
                           //"        <td valign=top>" + (AllowRss == 1 ? "RSS" : "---") + "</td>" +
                           "</tr>" + ReadingSub(belongSite, GroupNewsId, SubGroupNewsItemId, ref Ident);
                Ident = Ident - 5;
            }
            return RetHtml;
        }

        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            string GroupNewsId = (string)System.Web.HttpContext.Current.Request["GroupNewsId"];
            AjaxPro.Utility.RegisterTypeForAjax(typeof(GroupNewsItems));
            string RetHtml =
                WebPartUtilities.AttachJavascript("Portal.CMS", "GroupNews.js");

            string GroupNewsItemAddRootUrl = "javascript:ClientShowAddGroupNewsItemRootForm('" + GroupNewsId + "');";
            RetHtml +=
                Portal.Environment.Environments.GetFormDialog(
                "<div id=divProcessing></div>" +
                "<div id=divContentData>" + GetHtml(GroupNewsId) + "</div>", ResourceBLL.GetText(WebPartId, "GroupNewsItemHeader", "Chi tiết nhóm tin"));
            return RetHtml;
        }

        [AjaxPro.AjaxMethod]
        public string GetAddGroupNewsItemFormUrl(string GroupNewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsCls
                    GroupNewsCls = new GroupNewsBLL().CreateModel(GroupNewsId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");

                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "AddSubGroupNewsItem", GroupNewsId, GroupNewsCls.Owner, true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                new ParamCls("WebPartId",new AddGroupNewsItem().WebPartId),
                new ParamCls("GroupNewsId",GroupNewsId)
            });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }




        [AjaxPro.AjaxMethod]
        public string GetProcessingText()
        {
            return ResourceBLL.GetText(WebPartId, "ProcessingText", "Đang xử lý dữ liệu...");
        }

        [AjaxPro.AjaxMethod]
        public string GetAddSubGroupNewsItemFormUrl(string GroupNewsId, string ParentGroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, ParentGroupNewsItemId);
                
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");

                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "AddSubGroupNewsItem", GroupNewsItemCls.GroupNewsItemId, GroupNewsItemCls.Owner, true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                new ParamCls("WebPartId",new AddGroupNewsItem().WebPartId),
                new ParamCls("GroupNewsId",GroupNewsId),
                new ParamCls("ParentGroupNewsItemId",ParentGroupNewsItemId),
                });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string GetUpdateSubGroupNewsItemFormUrl(string GroupNewsId, string GroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);

        
                return Screen.BuildDialogUrl(new ParamCls[]{
                new ParamCls("WebPartId",new UpdateGroupNewsItem().WebPartId),
                new ParamCls("GroupNewsId",GroupNewsId),
                new ParamCls("GroupNewsItemId",GroupNewsItemId),
            });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmMsg()
        {
            return ResourceBLL.GetText(WebPartId,"ConfirmDeleteMsg","Bạn đã chắc chắn xóa chưa?");
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmPublicMsg()
        {
            return ResourceBLL.GetText(WebPartId,"ConfirmPublicMsg","Bạn đã chắc chắn xuất bản chưa?");
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideCheckDeleteGroupNewsItem(string GroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "DeleteGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideDeleteGroupNewsItem(string GroupNewsItemId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);

                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "DeleteGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);

        
                new GroupNewsBLL().DeleteGroupNewsItem(null, GroupNewsItemId);
                return ResourceBLL.GetText(WebPartId,"DeleteOkMessage","Xóa thành công");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSidePublishingGroupNewsItemRoot(string GroupNewsId, string GroupNewsItemId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);

                new GroupNewsBLL().PublicGroupNewsItemRoot(GroupNewsId, GroupNewsItemId);
                return ResourceBLL.GetText(WebPartId,"PublicOk","Xuất bản lên website (public) thành công");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideCheckAllowPublishingGroupNewsItemRoot(string GroupNewsId, string GroupNewsItemId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems"); Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSidePublishingGroupNewsItemSub(string GroupNewsId, string GroupNewsItemId, string SubGroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, SubGroupNewsItemId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingGroupNewsItem", SubGroupNewsItemId, GroupNewsItemCls.Owner, true);

                new GroupNewsBLL().PublicGroupNewsItemSub(GroupNewsId, GroupNewsItemId,SubGroupNewsItemId);
                return ResourceBLL.GetText(WebPartId,"PublicOk","Xuất bản lên website (public) thành công");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideCheckAllowPublishingGroupNewsItemSub(string GroupNewsId, string GroupNewsItemId, string SubGroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, SubGroupNewsItemId);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");

                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingGroupNewsItem", SubGroupNewsItemId, GroupNewsItemCls.Owner, true);
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetShowFormSetPermission(string GroupNewsItemId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new GroupNews().PermissionTypes, "GroupNewsItems");
                GroupNewsItemCls GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PermissionGroupNewsItem", GroupNewsItemId, GroupNewsItemCls.Owner, true);
                return Environment.Permission.GetPermissionUrl(WebPartId, GroupNewsItemId, "GroupNewsItems");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        public override bool IsMainWebPart
        {
            get
            {
                return true;
            }
        }

        public override bool RunStandalone
        {
            get
            {
                return false;
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetUpdateHtmlUrl(string GroupNewsId, string GroupNewsItemId)
        {
            return Screen.BuildDialogUrl(new GroupNewsHtml().WebPartId, new ParamCls[]{
                new ParamCls("GroupNewsId",GroupNewsId),
                new ParamCls("GroupNewsItemId",GroupNewsItemId),
            });
        }

        [AjaxPro.AjaxMethod]
        public string GetImageUrl(string GroupNewsId, string GroupNewsItemId)
        {
            return Screen.BuildDialogUrl(new UploadImageForGroupNews().WebPartId, new ParamCls[]{
                new ParamCls("GroupNewsId",GroupNewsId),
                new ParamCls("GroupNewsItemId",GroupNewsItemId),
            });
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideUpdateLevelIndex(string GroupNewsId)
        {
            try
            {
                new GroupNewsBLL().UpdateLevelIndex(GroupNewsId);
                return ResourceBLL.GetText(WebPartId, "UpdateOk", "Cập nhật thành công chỉ số cây!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideGetLink(string belongSite,string GroupNewsItemId)
        {
            try
            {
                GroupNewsItemCls GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                string LinkText = Environments.GetNewsCategoryUrl(belongSite, GroupNewsItemId, GroupNewsItemCls.GroupNewsItemName, "_runtime");
                LinkText = LinkText.Substring(LinkText.LastIndexOf("/") + 1);

                string LinkHtml = Environments.GetHtmlByMenu(belongSite, GroupNewsItemId, GroupNewsItemCls.GroupNewsItemName);
                LinkHtml = LinkHtml.Substring(LinkHtml.LastIndexOf("/") + 1);

                string RetHtml =
                "   <div><span class=cssViewItemType><a target=\"_blank\" href=\"" + Environments.HttpRoot + "/" + Environments.AppendAlias + "-" + belongSite + "/" + LinkText + "\">" + LinkText + "</a></span></div>" +
                "   <div><span class=cssViewItemType><a target=\"_blank\" href=\"" + Environments.HttpRoot + "/" + Environments.AppendAlias + "-" + belongSite + "/" + LinkHtml + "\">" + LinkHtml + "</a></span></div>";
                return RetHtml;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideSync(string GroupNewsItemId)
        {
            try
            {
                new GroupNewsBLL().SyncGroupNewsItemWithServer(GroupNewsItemId,false);
                return ResourceBLL.GetText(WebPartId,"SyncOk","Sync thành công với máy chủ");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideSyncWithNews(string GroupNewsItemId)
        {
            try
            {
                new GroupNewsBLL().SyncGroupNewsItemWithServer(GroupNewsItemId,true);
                return ResourceBLL.GetText(WebPartId, "SyncOkWithNews", "Sync nhóm và tin tức với máy chủ thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }
    }
}
